package craky.componentc;

import java.awt.Color;
import java.util.Vector;

import javax.swing.ListModel;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import com.abigdreamer.swing.component.UIResourceManager;

public class JCScrollList extends JCScrollPane
{
  private static final long serialVersionUID = -1708752774205915517L;
  private static final Color DISABLED_BG = UIResourceManager.getColor("TextDisabledBackground");
  private Border border;
  private Border disabledBorder;
  private Color background;
  protected JCList list;

  public JCScrollList(JCList list)
  {
    setViewportView(this.list = list);
    init();
  }

  public JCScrollList()
  {
    this(new JCList());
  }

  public JCScrollList(Vector<?> listData)
  {
    this(new JCList(listData));
  }

  public JCScrollList(ListModel dataModel)
  {
    this(new JCList(dataModel));
  }

  private void init()
  {
    setBorder(new LineBorder(new Color(84, 165, 213)));
    setDisabledBorder(new LineBorder(new Color(84, 165, 213, 128)));
    setBackground(UIResourceManager.getWhiteColor());
    setHeaderVisible(false);
    this.list.setBorder(new EmptyBorder(0, 0, 0, 0));
    this.list.setDisabledBorder(this.list.getBorder());
    this.list.setVisibleInsets(0, 0, 0, 0);
    this.list.setAlpha(0.0F);
  }

  public Border getDisabledBorder()
  {
    return this.disabledBorder;
  }

  public void setDisabledBorder(Border disabledBorder)
  {
    this.disabledBorder = disabledBorder;

    if (!isEnabled())
    {
      super.setBorder(disabledBorder);
    }
  }

  public void setBorder(Border border)
  {
    this.border = border;
    super.setBorder(border);
  }

  public Color getDisabledForeground()
  {
    return this.list.getDisabledForeground();
  }

  public void setDisabledForeground(Color disabledForeground)
  {
    this.list.setDisabledForeground(disabledForeground);
  }

  public void setEnabled(boolean enabled)
  {
    super.setEnabled(enabled);
    super.setBorder(enabled ? this.border : this.disabledBorder);
    super.setBackground(enabled ? this.background : DISABLED_BG);
  }

  public void setBackground(Color background)
  {
    this.background = background;
    super.setBackground(background);
  }

  public JCList getList()
  {
    return this.list;
  }
}